#ifndef _BACKDRO_PLAYER_H_
#define _BACKDRO_PLAYER_H_

#include "ui/ui_sprite.h"
#include "script/scripthelper.h"
#include "script/write_lua.h"

namespace backdrop
{
class BackdropScroll;
class Decal;

class BackdropLayer
{
public:
	BackdropLayer(BackdropScroll* pBackdrop);
	virtual ~BackdropLayer();

	virtual bool		Create(const std::string& File, const bool& UVScroll = true, const float& ParallaxFactor = 1.0f);
	void				Setup(const math::Vec2& pos);
	virtual void		Setup(const math::Vec2& pos, const math::Vec2& size);
	virtual void		Scroll(const math::Vec2& pos, bool bRelative = true);
	virtual void		Tick(float dt);
	virtual void		Render();
	void				RenderDecals();
	void				ResetLayer();
	void				ResetDecals();

	void				AddDecalSprite(Decal* pDecal);
	Decal*				GetDecalSprite(const math::Vec2& Pos);
	bool				DropDecalSprite(Decal* pDecal, bool bDelete = true);
	void				ClearDecals();
	void				LoadDecals(LuaPlus::LuaObject& Data);
	void				SaveDecals(script::WriteLua& Output);

	bool				IsUVScroll() const { return m_UVScroll; }
	bool				IsVisible() const { return m_IsVisible; }
	bool				IsEnabled() const { return m_IsEnabled; }
	bool				IsEmpty() { return (!m_Sprite.IsValid() && m_Decals.empty()); }
	float				GetParallax() const { return m_ParallaxFactor; }
	const math::Vec2&	GetOffset() { return m_Offset; }
	const math::Vec2&	GetPos() { return m_Pos; }
	const math::Vec2&	GetSize() { return m_Size; }
	const std::string&	GetName() { return m_Name; }
	void				GetRealSize(math::Vec2& size);
	void				GetVisibleDim(math::Vec2& size);

	void				SetIsVisible(bool Visible = true) { m_IsVisible = Visible; }
	void				SetIsEnabled(bool Enabled = true) { m_IsEnabled = Enabled; }

protected:
	void				UpdateUV();

	virtual COLOR		EnabledColor() const { return 0xFFFFFFFF; }
	virtual COLOR		DisabledColor() const { return 0x7F7F7F7F; }

	ui::UISprite		m_Sprite;
	math::Vec2			m_Pos;
	math::Vec2			m_Size;
	math::Vec2			m_Offset;
	float				m_ParallaxFactor;

	std::vector<Decal*>	m_Decals;

private:
	void				RenderSprite();

	BackdropScroll*		m_pBackdrop;
	int					m_Width;
	int					m_Height;
	bool				m_UVScroll;
	bool				m_IsVisible;
	bool				m_IsEnabled;

	std::string			m_Name;

	static int			m_ScreenW;
	static int			m_ScreenH;
};
} // namespace backdrop

#endif // _BACKDROP_LAYER_H_
